/*
 * Copyright 2016 Yan Zhenjie
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mingmen.canting.caigourenyuan;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.bumptech.glide.Glide;
import com.mingmen.canting.R;
import com.mingmen.canting.base.BaseBean;
import com.mingmen.canting.defineview.GlideRoundTransform;
import com.mingmen.canting.http.callback.StringCallback;
import com.mingmen.canting.httpconfig.AppConfig;
import com.mingmen.canting.httpconfig.HttpResponse;
import com.mingmen.canting.immersionbar.ImmersionBar;
import com.mingmen.canting.model.ZiZhiModel;
import com.mingmen.canting.util.GsonUtil;
import com.mingmen.canting.util.SharePreferenceUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;


/**
 * <p>
 * ListView形式的侧滑菜单，支持横向和竖向的。
 * </p>
 * Created by Yan Zhenjie on 2016/7/27.
 */
public class ChaKanZiZhiActivity extends Activity {

    @BindView(R.id.text_return)
    TextView textReturn;
    @BindView(R.id.linear_return)
    LinearLayout linearReturn;
    @BindView(R.id.text_center)
    TextView textCenter;
    @BindView(R.id.img_right)
    ImageView imgRight;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.mToolbar)
    Toolbar mToolbar;

    String token;
    String supplierId;
    @BindView(R.id.test_results)
    TextView test_results;
    @BindView(R.id.address)
    TextView address;
    @BindView(R.id.text_yingye)
    TextView text_yingye;
    @BindView(R.id.legalPerson)
    TextView legalPerson;
    @BindView(R.id.license)
    TextView license;
    @BindView(R.id.scope)
    TextView scope;
    @BindView(R.id.time)
    TextView time;
    String licenseStr;
    String picture;
    @BindView(R.id.img_zizhiOne)
    ImageView img_zizhiOne;
    @BindView(R.id.img_zizhiTwo)
    ImageView img_zizhiTwo;
    Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zizhil);
        ButterKnife.bind(this);
        textCenter.setText("查看资质");
        ImmersionBar.with(this).titleBar(mToolbar)
                .navigationBarColor(R.color.black).init();
        mContext=this;
        token = (String) SharePreferenceUtil.get(this, "token", "");
        supplierId = getIntent().getStringExtra("supplierId");
        licenseStr = getIntent().getStringExtra("license");
        picture = getIntent().getStringExtra("picture");
        Glide.with(mContext).load(AppConfig.IMGURL +licenseStr).dontAnimate().placeholder(R.mipmap.zhanwei).error(R.mipmap.zhanwei).transform(new GlideRoundTransform(mContext, 5)).into(img_zizhiOne);
        Glide.with(mContext).load(AppConfig.IMGURL +picture).dontAnimate().placeholder(R.mipmap.zhanwei).error(R.mipmap.zhanwei).transform(new GlideRoundTransform(mContext, 5)).into(img_zizhiTwo);
        HttpResponse.getSupplierQualification(token, supplierId, new StringCallback(this) {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                Log.d("CHAKANZIZHI", s);
                BaseBean baseBean = new BaseBean();
                baseBean = GsonUtil.GsonToBean(s, BaseBean.class);
                if (baseBean.getCode() == 0) {
                    ZiZhiModel ziZhiModel = new ZiZhiModel();
                    ziZhiModel = GsonUtil.GsonToBean(s, ZiZhiModel.class);
                    test_results.setText("检测结果:  "+ziZhiModel.getData().get(0).getTest_results());
                    address.setText(ziZhiModel.getData().get(0).getSupplierName());
                    text_yingye.setText(ziZhiModel.getData().get(0).getAddress());
                    legalPerson.setText(ziZhiModel.getData().get(0).getLegalPerson());
                    license.setText(ziZhiModel.getData().get(0).getLicense());
                    scope.setText(ziZhiModel.getData().get(0).getScope());
                    time.setText(ziZhiModel.getData().get(0).getValidityTerm());
                }


            }
        });

    }


    @OnClick({R.id.text_return, R.id.linear_return})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.text_return:
                finish();
                break;
            case R.id.linear_return:
                finish();
                break;


        }
    }
}